﻿using AuthCenter.Domain;
using AuthCenter.ErorCode;
using AuthCenter.Infrastructure;
using AuthCenter_API.Read.Applications.Commands.Audit;
using AutoMapper.Configuration.Annotations;
using MediatR;

namespace AuthCenter_API.Read.Applications.CommandHandlers.Audit
{
    public class AuditDepQueryCommandHandler : IRequestHandler<AuditDepQueryCommand, APIResult<List<DepModel>>>
    {
        private readonly IBaseRepository<DepModel> _depRepository;

        public AuditDepQueryCommandHandler(IBaseRepository<DepModel> depRepository)
        {
            _depRepository = depRepository;
        }

        public Task<APIResult<List<DepModel>>> Handle(AuditDepQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<DepModel>> result=new APIResult<List<DepModel>>();
            result.Code = APIEnum.QuerySuccess;
            result.Message = APIEnum.QuerySuccess.Desc();
            var m = _depRepository.GetAll().ToList();
            result.Data = m;    
            return Task.FromResult(result);
        }
    }
}
